//
//  FQMineAdController.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/11.
//

import UIKit

class FQMineAdController: BaseListSectionController {
    var model : FQMineAdModel!
    
    override init() {
        super.init()
        inset = UIEdgeInsets(top: 16, left: 20, bottom: 0, right: 20)
    }
    
    override func sizeForItem(at index: Int) -> CGSize {
        CGSize(width: SCREEN_WIDTH - 40, height: 113~)
    }
    
    override func cellForItem(at index: Int) -> UICollectionViewCell {
        let cell = dequeueReusableCell(cellType: FQMineAdCollectionViewCell.self, index: index)
        cell.model = model
        cell.buttonBlock = {
            let configModel = YHBaseConfiguration.shared.configModel ?? WMConfigModel()
            let newModel = BaseUserModel.unarchiver()!
            if (configModel.face == false || newModel.isFace == true)
                && (configModel.relationship == false || newModel.isAccomplishRelationship)
                && (configModel.education == false || newModel.isAccomplishEducation)
                && (configModel.workInformation == false || newModel.isAccomplishWorkInfo)
                && (configModel.loanAssistance == false || newModel.completeInformation)
                && (configModel.loanInformation == false || newModel.isAccomplishLoanInfo) {
                let vc = FQIDCardAuthViewController()
                self.viewController?.navigationController?.qmui_pushViewController(vc, animated: true)
            } else {
                NetworkManager.manager.request(targetType: .routeProductInfo, responseModelType: NetworkBaseModel<FQOrganizationModel>.self) { responseModel in
                    if responseModel.code != .successCode {
                        QMUITips.showError(responseModel.msg)
                        return
                    }
                    let vc = BaseWebViewController(.network(responseModel.data?.url))
                    self.viewController?.navigationController?.qmui_pushViewController(vc, animated: true)
                }
            }
        }
        return cell
    }
    
    override func didUpdate(to object: Any) {
        model = object as? FQMineAdModel
    }
}
